#include"game.h"


//
//开始界面
menu()
{
    printf("*************************\n");
    printf("******* 1.paly **********\n");
    printf("******* 0.exit **********\n");
    printf("*************************\n");
}

//游戏程序
game() 
{
    char board[ROW][COL]={0};
    //初始化棋盘
    InitBoard(board,ROW,COL);
    //展示棋盘
    PlayBoard(board,ROW,COL);
    int eq=0;
    while (1)
    {
        
        //玩家下棋
        PlayerMove(board,ROW,COL);
        eq++;
        PlayBoard(board,ROW,COL);
        //判断胜利
        int ret=Win(board,ROW,COL);
        if (ret==1)
        {
            printf("玩家胜利\n");
            break;
        }
        //判断平局
        if (eq==ROW*COL)
        {
            printf("平局\n");
            break;
        }
        //电脑下棋
        ComputerMove(board,ROW,COL);
        eq++;
        PlayBoard(board,ROW,COL);
        //判断胜利
        ret=Win(board,ROW,COL);
        if  (ret==2)
        {
            printf("电脑胜利\n");
            break;
        }
    }
    
}

//主程序
int main() 

{   
    int input=0;
    srand((unsigned int)time(NULL));

    do
    {   
        menu();
        printf("请选择：\n");
        scanf("%d",&input);
        switch (input)
        {
        case 1:
            game();
            break;
        case 0:
            printf("游戏退出");
            break;
        default:
            printf("选择错误，请重选：\n");
            break;
        }
        

    } while (input);
    
    return 0;
}